from django.contrib.auth.models import User
from django.shortcuts import render
from django.views import View
from rest_framework import generics, mixins, viewsets
from rest_framework.viewsets import GenericViewSet

from .filters import UserFilter
from .serializers import RegisterSerializer, UsersInfoSerializers


# 用户注册api主题
class UserView(mixins.CreateModelMixin,
               GenericViewSet):
    serializer_class = RegisterSerializer
    permission_classes = []


# 用户信息api主题
class UserInfoViewset(viewsets.ReadOnlyModelViewSet):
    """
    retrieve:
        返回指定用户信息
    list:
        返回用户列表
    """
    queryset = User.objects.all()
    serializer_class = UsersInfoSerializers
    filter_class = UserFilter
    filter_fields = ("username",)
    extra_perm_map = {
        "GET": ['auth.view_user']
    }
